<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
set_time_limit(0);
$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/SourceSite-utf8/secure";
include("/home/share/www/SourceSite-utf8/secure/config.inc.php");

$arrWeb = explode(",", $_data["AllWeb"]);
//include("AllWeb.inc.php");

$intGroup = (int)$_data["Group"];
if(empty($intGroup))$intGroup = 1;
$strCreditRange = trim($_data["CreditRange"]);

$arrCreditRange = explode(",", $strCreditRange);
$arrRange = array();
foreach($arrCreditRange as $intCredit){
	$arrRange[] = (int)$intCredit;
}
if(sizeof($arrRange))$arrRange = array(10000, 50000, 100000, 200000, 300000, 400000, 500000, 1000000);
$arrGroup = array(1 => '會員', 2 => '代理商', 3 => '總代理', 4 => '股東', 5 => '總監');

$strTmp1 = "<tr>
	<td class='web-name'>{No}</td>
	<td class='web-name'>{Web}</td>
	%s
</tr>";

$strTmp2 = "<td class='web-td'>%d</td>";

$intTotalN = 0;
$intTotalM = 0;
$flTotalR = 0;
$arrDB = array();
$strCon = "";
$intNo = 0;

$_isDBExist = "no";
$_DBSite = "Master";

$strSQL = "select `CreditLine`  from `bet_Member` where MemberGroup = ".$intGroup;
$arrTolUserNo = array();
foreach($arrWeb as $strWeb){
	$_blDBHostM = "";
	include("/home/share/www/".$strWeb."/secure/db.inc.php");
	if($_blDBHostM == "")continue;

	$strT1 = $strTmp1;
	$strT1 = str_replace("{Web}", $strWeb." -- {".$strWeb."} &nbsp;(".$_blDBHostM.")", $strT1);
	$intNo++;
	$strT1 = str_replace("{No}", $intNo, $strT1);

	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	$arrUserNo = array();
	while($Rows = PMA_mysql_fetch_object($RS)){
		
		foreach($arrRange as $k => $intCredit){
			if($Rows -> CreditLine <= $intCredit){
				$arrUserNo[$k]++;
				$arrTolUserNo[$k]++;
				break;
			}
		}

		if($Rows -> CreditLine > $arrRange[(sizeof($arrRange) - 1)]){
			$arrUserNo[sizeof($arrRange)]++;
			$arrTolUserNo[sizeof($arrRange)]++;
		}
	}

	$strT = "";
	foreach($arrRange as $k => $intCredit){
		$strT .= sprintf($strTmp2, $arrUserNo[$k]);
	}
	$strT .= sprintf($strTmp2, $arrUserNo[$k + 1]);
	$strCon .= sprintf($strT1, $strT);

	@mysql_free_result($RS);
	@mysql_close($$_Conn);
}

$strTmp1 = str_replace("{Web}", "Sum", $strTmp1);
$strTmp1 = str_replace("{No}", "", $strTmp1);

$strT = "";

foreach($arrRange as $k => $intCredit){
	$strT .= sprintf($strTmp2, $arrTolUserNo[$k]);
}
$strT .= sprintf($strTmp2, $arrTolUserNo[$k + 1]);
$strCon .= sprintf($strTmp1, $strT);

?><!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Report </title>
<style>
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #EFFFDF;
}
td {
	font-size: 12px
	font-family: Arial, Helvetica, Verdana, Geneva,  sans-serif;
	background-color: #FFFFFF;
	text-align: center;
}
.showTable {
	background-color: #9DBAD8;
	border: 1px solid #056FD8;
}
.web-td {
	text-align: right;
	padding-right: 2px;
}
.web-name {
	text-align: left;
	padding-left: 2px;
}
//-->
</style>
</head>

<body>
<table  border="0" cellspacing="1" cellpadding="0" class="showTable">
<tr>
    <td colspan="2">&nbsp;</td>
	<td colspan="<?php print (sizeof($arrRange) + 1);?>"><?php print $arrGroup[$intGroup];?></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<?php
foreach($arrRange as $intCredit){
	print '<td> 小於 '.($intCredit / 10000).'萬 </td>';
}
print '<td> 超過 '.($intCredit / 10000).'萬 </td>';
?>
</tr>
<?php print $strCon;?>
</table>
現在時間：<?php print date("Y-m-d H:i:s");?><br /><br />
</body>
</html>